package com.gc.server.controller.api;

import com.gc.server.entity.LevelEntity;
import com.gc.server.enums.LevelTypeEnum;
import com.gc.server.service.LevelService;
import com.yf.annotation.IgnoreAuth;
import com.yf.response.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/level")
public class ApiLevelController {

    @Autowired
    private LevelService levelService;

    @RequestMapping("/pub")
    @IgnoreAuth
    public R pubLevel(Long pid) {
        List<LevelEntity> list = levelService.findByType(LevelTypeEnum.PUB.getIndex());
        //返回级别比上级ID小的
        if (pid != null) {
            LevelEntity levelEntity = levelService.findByUserId(pid);
            if(levelEntity!=null){
                list = list.stream().filter(item -> item.getLv() < levelEntity.getLv()&&levelEntity.getType().equals(LevelTypeEnum.PUB.getIndex())).collect(Collectors.toList());
            }
        }
        return R.ok(list);
    }


}
